package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class LoanContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LoanContainer
{
    private ArrayList<Loan> lo;
    //private ArrayList<LoanContainer> lc;
    private static LoanContainer instance;
    //private ArrayList<Person> person;
    //private ArrayList<Dvd> dvd;
    private AddressBook adr;
    private DvdContainer dvctr;
    //private ArrayList<eksemplar> ex;
    
    
    private LoanContainer()
    {
        lo = new ArrayList<Loan>();
        //lc = new ArrayList<LoanContainer>();
        //dvd = new ArrayList<Dvd>();
        //person = new ArrayList<Person>();
        adr = AddressBook.getInstance();
        dvctr = DvdContainer.getInstance();
        //ex = new ArrayList<eksemplar>();
    }
    
    public static LoanContainer getInstance()
    {
        if(instance == null)
        {
            instance = new LoanContainer();
        }
        return instance;
    }
    
/*    public void listPerson(long id)
    {
        for(Person per : person)
        {
            if(per.getId() == id)
            {
                per.print();
            }
        }
    }
 */   
    public void addLoan(Loan loans)
    {
        lo.add(loans);
    }
    
    public Loan searchLoan(long id, String status)
    {
        int index = 0;
        int index2 = 0;
        boolean found = false;
        while(index < lo.size())
        {
            Loan loans = lo.get(index);
            if(loans.getId() == id && status == null)
            {
                found = true;
                index2 = index;
            }
            else if (loans.getStatus().equals(id))
            {
                found = true;
                index2 = index;
            }
            index++;
        }
        if(found == true)
        {
            return lo.get(index2);
        }
        else
        {
            return null;
        }
    }
    
/*    public void addPerson(Person pers)
    {
        person.add(pers);
    }
    
    public void addDvd(Dvd dvds)
    {
        dvd.add(dvds);
    }
    
    public void addEksemplar(eksemplar eks)
    {
        ex.add(eks);
    }
    
    /**
     * Search for a person in the LoanContainer
     * @param id The persons id
     * @param name The name of the person
     * @return Person The person object
     */
 /*   public Person searchPerson(long id, String name)
    {
        int index = 0;
        int index2 = 0;
        boolean found = true;
        while(index < person.size())
        {
            Person pers = person.get(index);
            if(pers.getId() == id && name == null)
            {
                found = true;
                index2 = index;
            }
            else if(pers.getName().equals(name) && id == 0)
            {
                found = true;
                index2 = index;
            }
            else if(pers.getId() == id && pers.getName().equals(name))
            {
                found = true;
                index2 = index;
            }
            index++;
        }
        if(found == true)
        {
            return person.get(index2);
        }
        else
        {
            return null;
        }
    }
*/   
    /**
     * Search the LoanContainer for a serial number
     * @param serienr The serial number of thd dvd
     * @return eksemplar The found eksemplar
     */
/*    public eksemplar searchEksemplar(String serienr)
    {
        int index = 0;
        int index2 = 0;
        boolean found = false;
        while( index < ex.size() &&  found != true)
        {
            eksemplar eks = ex.get(index);
            if(eks.getSerienr().equals(serienr))
            {
                found = true;
                index2 = index;
            }
            index++;
        }
        return ex.get(index2);
    }
  */  
    /**
     * List a dvd eksemplar in the LoanContainer
     * @param serienr The serial
     */
/*    public void listEksemplar(String serienr)
    {
        for( eksemplar eks : ex)
        {
            if(eks.getSerienr().equals(serienr))
            {
                eks.print();
            }
        }
    }
  */  
    /**
     * List a persons loan
     * @param id The persons id
     */
    public void listLoan(long id)
    {
        for(Loan loans : lo)
        {
            if(loans.getId() == id)
            {
                loans.print();
            }
        }
    }
/*    
    public void searchDvd(long id)
    {
        for(Dvd dvds : dvd)
        {
            if(dvds.getId() == id)
            {
                dvds.print();
            }
        }
     }
    
 */    

 /*   
    public void listAll(long id)
    {
        int index = 0;
        while(index < dvd.size())
        {
            Dvd dvds = dvd.get(index);
            if(dvds.getId() == id)
            {
                dvds.print();
            }
            index++;
        }
    }
  */  
    /**
     * Remove a persons loan
     * @param serialnr The serial number of the dvd
     */
/*    public void removeCopy(String serienr)
    {
        int index = 0;
        boolean found = false;
        while( index < ex.size() && found != true)
        {
            eksemplar eks = ex.get(index);
            if(eks.getSerienr().equals(serienr))
            {
                found = true;
                ex.remove(eks);
            }
            else
            {
                index++;
            }
            
        }
    }
    */
}
